package kyssion.leetcode.num51_100;

public class code64_最小路径和 {
    public static void main(String[] args) {

    }

    public int minPathSum(int[][] grid) {
        if(grid.length==0||grid[grid.length].length==0){
            return 0;
        }
        for (int a = 0; a < grid.length; a++) {
            if (a == 0) {
                for (int b = 1; b < grid[a].length; b++) {
                    grid[a][b] = grid[a][b - 1] + grid[a][b];
                }
                continue;
            }
            for (int b = 0; b < grid[a].length; b++) {
                if(b==0){
                    grid[a][b]=grid[a-1][b]+grid[a][b];
                }else{
                    grid[a][b]= Math.min(grid[a-1][b]+grid[a][b],grid[a][b-1]+grid[a][b]);
                }
            }
        }
        return grid[grid.length-1][grid[grid.length-1].length-1];
    }
}
